<template>
  <el-dropdown
    style="
      cursor: pointer;
      float: right;
      margin-right: 60px;
      margin-left: 20px;
      z-index: 1200;
    "
  >
    <span class="el-dropdown-link">
      <div class="el-dropdown-link-item">
        <el-avatar>{{ userInfo.nickname }}</el-avatar>
        <i
          class="el-icon-arrow-down el-icon--right"
          style="margin-right: 5px"
        ></i>
      </div>
    </span>
    <template #dropdown>
      <el-dropdown-menu style="text-align: center">
        <el-dropdown-item>
          <div
            @click="$router.push({ path: '/login', query: { to: '/' } })"
            v-if="!loginStatus"
          >
            登录
          </div>
        </el-dropdown-item>
        <el-dropdown-item v-if="loginStatus">
          <div @click="$router.push('/person')">个人信息</div>
        </el-dropdown-item>
        <el-dropdown-item v-if="loginStatus">
          <div @click="logout">退出</div>
        </el-dropdown-item>
      </el-dropdown-menu>
    </template>
  </el-dropdown>
</template>

<script setup lang="ts">
import { useRouter } from "vue-router";
import { useStore } from "vuex";

const store = useStore();
const router = useRouter();

// Props
const props = defineProps({
  userInfo: {
    type: Object,
    default: () => ({}),
  },
  loginStatus: {
    type: Boolean,
    default: true,
  },
  role: {
    type: String,
    default: "admin",
  },
});

// Methods
const logout = () => {
  localStorage.removeItem("user");
  router.go(0);
  store.state.message.success("退出成功");
};
</script>

<style scoped lang="less">
a {
  text-decoration: none;
}
.navagation {
  width: 100%;
  height: 60px;
  line-height: 60px;
  overflow: hidden;
}
.avatar {
  width: 45px;
  height: 45px;
  border-radius: 100%;
  position: relative;
}
.menu-item {
  padding-left: 50px;
  padding-right: 50px;
  background-color: var(--header-nav) !important;
}
.el-menu {
  background-color: var(--header-nav) !important;
}
.el-menu-item:not(.is-disabled):hover {
  color: var(--nav-text) !important;
  background-color: var(--header-nav) !important;
  background-color: var(--hover-bg) !important;
}
.el-menu-item.is-active {
  color: var(--nav-text) !important;
  border-bottom: solid 2px var(--nav-text) !important;
  background-color: var(--hover-bg) !important;
}
.good-menu a span {
  color: var(--classify-text);
}
.good-menu a span:hover {
  color: var(--classify-text-hover) !important;
}
.el-dropdown {
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
}
.el-dropdown-link-item {
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
}
</style>
